package com.baizhi.shane.shane.controller;

import com.baizhi.shane.common.base.Result;
import com.baizhi.shane.constant.ApiMapping;
import com.baizhi.shane.constant.TableNameMapping;
import com.baizhi.shane.shane.dto.AnswerMyPostedOutDTO;
import com.baizhi.shane.shane.entity.*;
import com.baizhi.shane.shane.service.*;
import com.baizhi.shane.shane.vo.*;
import com.baizhi.shane.sys.vo.IdVO;
import com.baizhi.shane.sys.vo.SuccessedOutVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 闻柏智
 * @date 2023/09/20 20:00:13
 */
@RestController
@RequestMapping(TableNameMapping.SHANE_ANSWER)
@Api(tags="回答表")
public class ShaneAnswerController {
    @Resource
    private ShaneAnswerService shaneAnswerService;
    @Resource
    private ShaneLikesAnswerService shaneLikesAnswerService;
    @Resource
    private ShaneCollectAnswerService shaneCollectAnswerService;
    @Resource
    private ShaneAgainstAnswerService shaneAgainstAnswerService;
    @Resource
    private ShaneCommentAnswerService shaneCommentAnswerService;

    /**
     * 新增一个回答
     *
     * @Author 闻柏智
     * @Date 17:14 2024/3/1
     * @Param answerInsertInVO
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.sys.vo.SuccessedOutVO>
     **/
    @ApiOperation(value="新增一个回答", notes="新增一个回答")
    @PostMapping(value = ApiMapping.INSERT_ONE)
    public Result<SuccessedOutVO> insertOne(
            @RequestBody AnswerInsertInVO answerInsertInVO
    ) {
        SuccessedOutVO successedOutVO = shaneAnswerService.insertOne(answerInsertInVO);
        return Result.OK(successedOutVO);
    }

    /**
     * 查询单个回答-原生
     *
     * @Author 闻柏智
     * @Date 22:40 2024/3/3
     * @Param answerId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.entity.ShaneAnswer>
     **/
    @ApiOperation(value="查询单个回答-原生", notes="查询单个回答-原生")
    @GetMapping(value = ApiMapping.GET_ONE_ORIGIN)
    public Result<ShaneAnswer> getOneOrigin(
            @RequestParam("answerId") @ApiParam("问题ID") Long answerId
    ) {
        ShaneAnswer shaneAnswer = shaneAnswerService.getById(answerId);
        return Result.OK(shaneAnswer);
    }

    /**
     * 通过ID编辑回答
     *
     * @Author 闻柏智
     * @Date 22:42 2024/3/3
     * @Param shaneAnswer
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.sys.vo.SuccessedOutVO>
     **/
    @ApiOperation(value="通过ID编辑回答", notes="通过ID编辑回答")
    @PostMapping(value = ApiMapping.UPDATE_ONE_BY_ID)
    public Result<SuccessedOutVO> updateOneById(
            @RequestBody ShaneAnswer shaneAnswer
    ) {
        SuccessedOutVO successedOutVO = shaneAnswerService.updateOneById(shaneAnswer);
        return Result.OK(successedOutVO);
    }
    
    /**
     * 通过关键字模糊查询回答列表
     *
     * @Author 闻柏智
     * @Date 21:27 2024/1/22
     * @Param pageInVO
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.PageAnswerOutVO>
     **/
    @ApiOperation(value="通过关键字模糊查询回答列表", notes="通过关键字模糊查询回答列表")
    @GetMapping(value = ApiMapping.PAGE_BY_CONTENT)
    public Result<PageAnswerOutVO> pageByContent(PageInVO pageInVO) {
        List<PageAnswerOutVO> pageAnswerOutVOList = shaneAnswerService.pageByContent(pageInVO);
        return Result.OK(pageAnswerOutVOList);
    }

    /**
     * 我发布过的回答
     *
     * @Author 闻柏智
     * @Date 21:32 2024/3/3
     * @Param
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.dto.AnswerMyPostedOutDTO>
     **/
    @ApiOperation(value="我发布过的回答", notes="我发布过的回答")
    @GetMapping(value = ApiMapping.MY_POSTED)
    public Result<AnswerMyPostedOutDTO> myPosted() {
        List<AnswerMyPostedOutDTO> shaneAnswerList = shaneAnswerService.myPosted();
        return Result.OK(shaneAnswerList);
    }

    /**
     * 我收藏的回答
     *
     * @Author 闻柏智
     * @Date 14:32 2024/3/4
     * @Param
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.entity.ShaneAnswer>
     **/
    @ApiOperation(value="我收藏的回答", notes="我收藏的回答")
    @GetMapping(value = ApiMapping.MY_COLLECTED)
    public Result<AnswerMyPostedOutDTO> myCollected() {
        List<AnswerMyPostedOutDTO> shaneAnswerList = shaneAnswerService.myCollected();
        return Result.OK(shaneAnswerList);
    }

    /**
     * 通过回答ID列表查询这些回答的标签列表
     *
     * @Author 闻柏智
     * @Date 15:23 2024/3/4
     * @Param idListStr
     * @return com.baizhi.shane.common.base.Result<java.util.List<com.baizhi.shane.shane.vo.AnswerLabelOutVO>>
     **/
    @ApiOperation(value="通过回答ID列表查询这些回答的标签列表", notes="通过回答ID列表查询这些回答的标签列表")
    @GetMapping(value = ApiMapping.GET_ANSWER_LABEL_LIST_BY_ANSWER_ID_LIST)
    public Result<List<AnswerLabelOutVO>> getAnswerLabelListByAnswerIdList(@RequestParam("idListStr") @ApiParam("多个id用','分割") String idListStr) {
        List<AnswerLabelOutVO> AnswerLabelOutVOList = shaneAnswerService.getAnswerLabelListByAnswerIdList(idListStr);
        return Result.OK(AnswerLabelOutVOList);
    }

    /**
     * 通过回答ID查询单个回答的标签
     *
     * @Author 闻柏智
     * @Date 15:38 2024/3/4
     * @Param answerId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.AnswerLabelOutVO>
     **/
    @ApiOperation(value="通过回答ID查询单个回答的标签", notes="通过回答ID查询单个回答的标签")
    @GetMapping(value = ApiMapping.GET_ANSWER_LABEL_BY_ANSWER_ID)
    public Result<AnswerLabelOutVO> getAnswerLabelByAnswerId(@RequestParam("answerId") @ApiParam("回答ID") Long answerId) {
        AnswerLabelOutVO AnswerLabelOutVO = shaneAnswerService.getAnswerLabelByAnswerId(answerId);
        return Result.OK(AnswerLabelOutVO);
    }

    /**
     * 通过关键字查询回答列表的元素数量和分页个数
     *
     * @Author 闻柏智
     * @Date 16:06 2024/3/4
     * @Param pageInVO
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.CountAndPageOutVO>
     **/
    @ApiOperation(value="通过关键字查询回答列表的元素数量和分页个数", notes="通过关键字查询回答列表的元素数量和分页个数")
    @GetMapping(value = ApiMapping.COUNT_AND_PAGE_BY_CONTENT)
    public Result<CountAndPageOutVO> countAndPageByContent(PageInVO pageInVO ) {

        CountAndPageOutVO successedOutVO = shaneAnswerService.countAndPageByContent(pageInVO);

        return Result.OK(successedOutVO);
    }

    /**
     * 删除一个回答-通过ID
     *
     * @Author 闻柏智
     * @Date 16:13 2024/3/4
     * @Param idVO
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.sys.vo.SuccessedOutVO>
     **/
    @ApiOperation(value="删除一个回答-通过ID", notes="删除一个回答-通过ID")
    @PostMapping(value = ApiMapping.DELETE_ONE_ANSWER_BY_ID)
    public Result<SuccessedOutVO> deleteOneAnswerById(@RequestBody IdVO idVO) {

        SuccessedOutVO successedOutVO = shaneAnswerService.deleteOneAnswerById(idVO);

        return Result.OK(successedOutVO);
    }

    /**
     * 用户点赞回答，只需要answerId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 19:22 2023/10/4
     * @Param answerUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户点赞回答", notes="用户点赞回答")
    @PostMapping(value = ApiMapping.INSERT_ONE_ANSWER_LIKES)
    public Result<String> insertOneAnswerLikes(@RequestBody AnswerUserRelVO answerUserRelVO) {

        String succeed = shaneLikesAnswerService.insertOneAnswerLikes(answerUserRelVO);

        return Result.OK(succeed);
    }

    /**
     * 用户取消点赞回答，只需要answerId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 19:27 2023/10/4
     * @Param answerUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户取消点赞回答", notes="用户取消点赞回答")
    @PostMapping(value = ApiMapping.DELETE_ONE_ANSWER_LIKES)
    public Result<String> deleteOneAnswerLikes(@RequestBody AnswerUserRelVO answerUserRelVO) {

        String succeed = shaneLikesAnswerService.deleteOneAnswerLikes(answerUserRelVO);

        return Result.OK(succeed);
    }

    /**
     * 用户收藏回答，只需要answerId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 19:34 2023/10/4
     * @Param answerUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户收藏回答", notes="用户收藏回答")
    @PostMapping(value = ApiMapping.INSERT_ONE_ANSWER_COLLECT)
    public Result<String> insertOneAnswerCollect(@RequestBody AnswerUserRelVO answerUserRelVO) {

        String succeed = shaneCollectAnswerService.insertOneAnswerCollect(answerUserRelVO);

        return Result.OK(succeed);
    }

    /**
     * 用户取消收藏回答，只需要answerId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 19:40 2023/10/4
     * @Param answerUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户取消收藏回答", notes="用户取消收藏回答")
    @PostMapping(value = ApiMapping.DELETE_ONE_ANSWER_COLLECT)
    public Result<String> deleteOneAnswerCollect(@RequestBody AnswerUserRelVO answerUserRelVO) {

        String succeed = shaneCollectAnswerService.deleteOneAnswerCollect(answerUserRelVO);

        return Result.OK(succeed);
    }
    
    /**
     * 用户反对回答，只需要answerId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 16:37 2023/10/12
     * @Param answerUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户反对回答", notes="用户反对回答")
    @PostMapping(value = ApiMapping.INSERT_ONE_ANSWER_AGAINST)
    public Result<String> insertOneAnswerAgainst(@RequestBody AnswerUserRelVO answerUserRelVO) {

        String succeed = shaneAgainstAnswerService.insertOneAnswerAgainst(answerUserRelVO);

        return Result.OK(succeed);
    }

    /**
     * 用户取消反对回答，只需要answerId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 16:42 2023/10/12
     * @Param answerUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户取消反对回答", notes="用户取消反对回答")
    @PostMapping(value = ApiMapping.DELETE_ONE_ANSWER_AGAINST)
    public Result<String> deleteOneAnswerAgainst(@RequestBody AnswerUserRelVO answerUserRelVO) {

        String succeed = shaneAgainstAnswerService.deleteOneAnswerAgainst(answerUserRelVO);

        return Result.OK(succeed);
    }

    /**
     * 获取指定回答下所有的评论
     *
     * @Author 闻柏智
     * @Date 15:06 2024/2/28
     * @Param answerId
     * @return com.baizhi.shane.common.base.Result<java.util.List<com.baizhi.shane.shane.vo.CommentAnswerVO>>
     **/
    @ApiOperation(value="获取指定回答下所有的评论", notes="获取指定回答下所有的评论")
    @GetMapping(value = ApiMapping.GET_ALL_COMMENT_BY_ANSWER_ID)
    public Result<List<CommentAnswerVO>> getAllCommentByAnswerId(@RequestParam Long answerId) {
        List<CommentAnswerVO> commentAnswerVOList = shaneCommentAnswerService.getAllCommentByAnswerId(answerId);
        return Result.OK(commentAnswerVOList);
    }

    /**
     * 新增一个评论
     *
     * @Author 闻柏智
     * @Date 10:16 2024/2/28
     * @Param shaneCommentAnswer
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.sys.vo.SuccessedOutVO>
     **/
    @ApiOperation(value="新增一个评论", notes="新增一个评论")
    @PostMapping(value = ApiMapping.INSERT_ONE_COMMENT)
    public Result<SuccessedOutVO> insertOneComment(@RequestBody ShaneCommentAnswer shaneCommentAnswer) {
        SuccessedOutVO successedOutVO = shaneCommentAnswerService.insertOneComment(shaneCommentAnswer);
        return Result.OK(successedOutVO);
    }

    /**
     * 通过问题ID列表查询这些问题的点赞数量
     *
     * @Author 闻柏智
     * @Date 20:28 2024/1/21
     * @Param answerIdList
     * @return com.baizhi.shane.common.base.Result<java.util.List<com.baizhi.shane.shane.vo.CountVO>>
     **/
    @ApiOperation(value="通过回答ID列表查询这些回答的点赞数量", notes="通过回答ID列表查询这些回答的点赞数量")
    @PostMapping(value = ApiMapping.GET_ANSWER_LIKE_COUNT_BY_ANSWER_ID_LIST)
    public Result<List<CountVO>> getAnswerLikeCountByAnswerIdList(@RequestBody List<Long> answerIdList ) {
        List<CountVO> countVOList = this.shaneAnswerService.getAnswerLikeCountByAnswerIdList(answerIdList);
        return Result.OK(countVOList);
    }

    /**
     * 通过回答ID查询单个回答的点赞数量
     *
     * @Author 闻柏智
     * @Date 20:35 2024/1/21
     * @Param answerId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.CountVO>
     **/
    @ApiOperation(value="通过回答ID查询单个回答的点赞数量", notes="通过回答ID查询单个回答的点赞数量")
    @GetMapping(value = ApiMapping.GET_ONE_ANSWER_LIKE_COUNT_BY_ANSWER_ID)
    public Result<CountVO> getOneAnswerLikeCountByAnswerId(Long answerId ) {
        CountVO countVO = this.shaneAnswerService.getOneAnswerLikeCountByAnswerId(answerId);

        return Result.OK(countVO);
    }

    /**
     * 通过回答ID列表查询这些回答的反对数量
     *
     * @Author 闻柏智
     * @Date 21:01 2024/1/21
     * @Param answerIdList
     * @return com.baizhi.shane.common.base.Result<java.util.List<com.baizhi.shane.shane.vo.CountVO>>
     **/
    @ApiOperation(value="通过回答ID列表查询这些回答的反对数量", notes="通过回答ID列表查询这些回答的反对数量")
    @PostMapping(value = ApiMapping.GET_ANSWER_AGAINST_COUNT_BY_ANSWER_ID_LIST)
    public Result<List<CountVO>> getAnswerAgainstCountByAnswerIdList(@RequestBody List<Long> answerIdList ) {
        List<CountVO> countVOList = this.shaneAnswerService.getAnswerAgainstCountByAnswerIdList(answerIdList);
        return Result.OK(countVOList);
    }

    /**
     * 通过回答ID查询单个回答的反对数量
     *
     * @Author 闻柏智
     * @Date 21:03 2024/1/21
     * @Param answerId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.CountVO>
     **/
    @ApiOperation(value="通过回答ID查询单个回答的反对数量", notes="通过回答ID查询单个回答的反对数量")
    @GetMapping(value = ApiMapping.GET_ONE_ANSWER_AGAINST_COUNT_BY_ANSWER_ID)
    public Result<CountVO> getOneAnswerAgainstCountByAnswerId(Long answerId ) {
        CountVO countVO = this.shaneAnswerService.getOneAnswerAgainstCountByAnswerId(answerId);

        return Result.OK(countVO);
    }

    /**
     * 通过回答ID列表查询这些回答的收藏数量
     *
     * @Author 闻柏智
     * @Date 15:27 2024/1/22
     * @Param answerIdList
     * @return com.baizhi.shane.common.base.Result<java.util.List<com.baizhi.shane.shane.vo.CountVO>>
     **/
    @ApiOperation(value="通过回答ID列表查询这些回答的收藏数量", notes="通过回答ID列表查询这些回答的收藏数量")
    @PostMapping(value = ApiMapping.GET_ANSWER_COLLECT_COUNT_BY_ANSWER_ID_LIST)
    public Result<List<CountVO>> getAnswerCollectCountByAnswerIdList(@RequestBody List<Long> answerIdList ) {
        List<CountVO> countVOList = this.shaneAnswerService.getAnswerCollectCountByAnswerIdList(answerIdList);
        return Result.OK(countVOList);
    }

    /**
     * 通过回答ID查询单个回答的收藏数量
     *
     * @Author 闻柏智
     * @Date 15:33 2024/1/22
     * @Param answerId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.CountVO>
     **/
    @ApiOperation(value="通过回答ID查询单个回答的收藏数量", notes="通过回答ID查询单个回答的收藏数量")
    @GetMapping(value = ApiMapping.GET_ONE_ANSWER_COLLECT_COUNT_BY_ANSWER_ID)
    public Result<CountVO> getOneAnswerCollectCountByAnswerId(Long answerId ) {
        CountVO countVO = this.shaneAnswerService.getOneAnswerCollectCountByAnswerId(answerId);
        return Result.OK(countVO);
    }

    /**
     * 通过回答ID列表查询这些回答的评论数量
     *
     * @Author 闻柏智
     * @Date 15:37 2024/1/22
     * @Param answerIdList
     * @return com.baizhi.shane.common.base.Result<java.util.List<com.baizhi.shane.shane.vo.CountVO>>
     **/
    @ApiOperation(value="通过回答ID列表查询这些回答的评论数量", notes="通过回答ID列表查询这些回答的评论数量")
    @PostMapping(value = ApiMapping.GET_ANSWER_COMMENT_COUNT_BY_ANSWER_ID_LIST)
    public Result<List<CountVO>> getAnswerCommentCountByAnswerIdList(@RequestBody List<Long> answerIdList ) {
        List<CountVO> countVOList = this.shaneAnswerService.getAnswerCommentCountByAnswerIdList(answerIdList);
        return Result.OK(countVOList);
    }

    /**
     * 通过回答ID列表查询这些回答的评论数量
     *
     * @Author 闻柏智
     * @Date 15:39 2024/1/22
     * @Param answerId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.CountVO>
     **/
    @ApiOperation(value="通过回答ID列表查询这些回答的评论数量", notes="通过回答ID列表查询这些回答的评论数量")
    @GetMapping(value = ApiMapping.GET_ONE_ANSWER_COMMENT_COUNT_BY_ANSWER_ID)
    public Result<CountVO> getOneAnswerCommentCountByAnswerId(Long answerId ) {
        CountVO countVO = this.shaneAnswerService.getOneAnswerCommentCountByAnswerId(answerId);
        return Result.OK(countVO);
    }

    /**
     * 通过ID查询单个回答信息
     *
     * @Author 闻柏智
     * @Date 16:11 2024/2/29
     * @Param answerId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.GetOneAnswerOutVO>
     **/
    @ApiOperation(value="通过ID查询单个回答信息", notes="通过ID查询单个回答信息")
    @GetMapping(value = ApiMapping.GET_ONE_ANSWER_BY_ID)
    public Result<GetOneAnswerOutVO> getOneAnswerById(@RequestParam("answerId") @ApiParam("回答ID") Long answerId) {
        GetOneAnswerOutVO getOneAnswerOutVO = this.shaneAnswerService.getOneAnswerById(answerId);

        return Result.OK(getOneAnswerOutVO);
    }




}
